/**
 * Copyright 2018-2019 jianggujin (www.jianggujin.com).
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.jianggujin.modulelink.config;

import com.jianggujin.modulelink.util.JAssert;

/**
 * 多版本模块配置信息
 * 
 * @author jianggujin
 *
 */
public class JMultiVersionModuleConfig extends JModuleConfig {
    /**
     * 模块的版本
     */
    private final String version;

    public JMultiVersionModuleConfig(String moduleName, String version) {
        super(moduleName);
        JAssert.checkNotNull(version, "version must not be null");
        this.version = version;
    }

    /**
     * 获得模块版本
     * 
     * @return 模块版本
     */
    public String getVersion() {
        return version;
    }

    @Override
    public int compareTo(JModuleConfig other) {
        int value = super.compareTo(other);
        if (value == 0 && (other instanceof JMultiVersionModuleConfig)) {
            return this.version.compareTo(((JMultiVersionModuleConfig) other).version);
        }
        return value;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = super.hashCode();
        result = prime * result + ((version == null) ? 0 : version.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        JMultiVersionModuleConfig other = (JMultiVersionModuleConfig) obj;
        if (this.getModuleName() == null) {
            if (other.getModuleName() != null) {
                return false;
            }
        } else if (!getModuleName().equals(other.getModuleName())) {
            return false;
        }
        if (version == null) {
            if (other.version != null) {
                return false;
            }
        } else if (!version.equals(other.version)) {
            return false;
        }
        return true;
    }
}
